package com.changli02.reference;

import com.changli02.reference.data.Employee;
import org.junit.Test;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

public class ConstructorRefTest {
    @Test
    public void test() {
        Supplier<Employee> supplier = new Supplier<Employee>() {
            public Employee get() {
                return new Employee();
            }
        };
        supplier.get();

        Supplier<Employee> supplier2 = Employee::new;
        supplier2.get();

    }
    @Test
    public void test2() {
        Function<String, Employee> function1 = new Function<String, Employee>() {

            @Override
            public Employee apply(String name) {
                return new Employee(name);
            }
        };



        Function<String, Employee> function = Employee::new;
        System.out.println(function.apply("Sail"));


    }

    @Test
    public void test3() {
        BiFunction<String,Integer,Employee> bf = new BiFunction<String,Integer,Employee>() {
            @Override
            public Employee apply(String name, Integer integer) {
                return new Employee(name, integer);
            }
        };
        System.out.println(bf.apply("Sail", 1));

        BiFunction<String,Integer,Employee> bf2 = Employee::new;
        System.out.println(bf2.apply("Sail", 1));



    }
    //数组引用
    @Test
     public void test4() {
        Function<Integer,Employee[]> f = new Function<Integer,Employee[]>() {

            @Override
            public Employee[] apply(Integer length) {
                return new Employee[length];
            }
        };
        System.out.println(f.apply(10).length);
        Function<Integer,Employee[]> f2 = Employee[]::new;
        System.out.println(f2.apply(10).length);
    }
}
